package com.example.demo.service.Impl;

import com.example.demo.entity.ClazzOption;
import com.example.demo.entity.JobOption;
import com.example.demo.mapper.EmpMapper;
import com.example.demo.mapper.StudentMapper;
import com.example.demo.service.reportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class reportServiceImpl implements reportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public JobOption getEmpJobCount() {
        //1.查询所有员工，统计每个部门下的员工数量
        List<Map<String,Object>> list = empMapper.countEmpJobData();
        List<Object> jobList = list.stream().map(m -> m.get("pos")).toList();
        List<Object> dataList = list.stream().map(m -> m.get("total")).toList();
        return new JobOption(jobList, dataList);
    }

    @Override
    public List<Map> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    /**
     * 获取学生学历数据
     * @return
     */
    @Override
    public List<Map> getStudentDegreeData() {
        return studentMapper.getStudentDegreeData();
    }

    /**
     * 统计各班级总人数
     * @return
     */
    @Override
    public ClazzOption getStudentCountData() {
        List<Map<String,Object>> list = studentMapper.getStudentCountData();
        List<Object> clazzList = list.stream().map(m -> m.get("pos")).toList();
        List<Object> dataList = list.stream().map(m -> m.get("total")).toList();
        return new ClazzOption(clazzList, dataList);
    }
}
